SlideShare a Scribd company logo
Quantization


                Yao Wang
Polytechnic University, Brooklyn, NY11201
       http://eeweb.poly.edu/~yao
Outline


• Review the three process of A to D conversion
• Quantization
      – Uniform
      – Non-uniform
           • Mu-law
      – Demo on quantization of audio signals
      – Sample Matlab codes
• Binary encoding
      – Bit rate of digital signals
• Advantage of digital representation



©Yao Wang, 2006                EE3414:Quantization   2
Three Processes in A/D Conversion


            Sampling                          Quanti-                Binary
                                              zation                 Encoding
xc(t)                     x[n] = xc(nT)                       x[n]              c[n]

             Sampling                      Quantization               Binary
              Period                         Interval                codebook
                T                               Q


        •    Sampling: take samples at time nT
              – T: sampling period;
              – fs = 1/T: sampling frequency
        •    Quantization: map amplitude values into a set of discrete values kQ
              – Q: quantization interval or stepsize
        •    Binary Encoding
              – Convert each quantized value into a binary codeword

 ©Yao Wang, 2006                        EE3414:Quantization                            3
Analog to Digital Conversion


              1
                                   T=0.1
                                   Q=0.25

            0.5



              0



            -0.5

                                                             A2D_plot.m

             -1


                   0   0.2   0.4            0.6    0.8   1




©Yao Wang, 2006              EE3414:Quantization                      4
How to determine T and Q?

• T (or fs) depends on the signal frequency range
      – A fast varying signal should be sampled more frequently!
      – Theoretically governed by the Nyquist sampling theorem
           • fs > 2 fm (fm is the maximum signal frequency)
           • For speech: fs >= 8 KHz; For music: fs >= 44 KHz;
• Q depends on the dynamic range of the signal amplitude and
  perceptual sensitivity
      – Q and the signal range D determine bits/sample R
           • 2R=D/Q
           • For speech: R = 8 bits; For music: R =16 bits;
• One can trade off T (or fs) and Q (or R)
      – lower R -> higher fs; higher R -> lower fs
• We considered sampling in last lecture, we discuss quantization
  in this lecture



©Yao Wang, 2006                    EE3414:Quantization              5
Uniform Quantization

• Applicable when the signal is in
a finite range (fmin, fmax)

• The entire data range is divided
into L equal intervals of length Q
(known as quantization interval or
quantization step-size)

      Q=(fmax-fmin)/L

• Interval i is mapped to the
middle value of this interval

• We store/send only the index of
                                                                                       f − f min 
quantized value                               Index of quantized value = Qi ( f ) = 
                                                                                     
                                                                                               Q 
                                              Quantized value = Q ( f ) = Qi ( f )Q + Q / 2 + f min

  ©Yao Wang, 2006                    EE3414:Quantization                                         6
Special Case I:
             Signal range is symmetric

• (a) L=even, mid-rise
Q(f)=floor(f/q)*q+q/2




     L = even, Mid - Riser                                       L = odd, Mid - Tread
                       f                            Q                             f
     Qi ( f ) = floor ( ), Q ( f ) = Qi ( f ) * Q +             Qi ( f ) = round ( ), Q( f ) = Qi ( f ) * Q
                       Q                            2                             Q

©Yao Wang, 2006                                  EE3414:Quantization                                          7
Special Case II:
                  Signal range starts at 0




                                                f min = 0, B = f max , q = f max / L
                                                                  f
                                                Qi ( f ) = floor ( )
                                                                  Q
                                                                          Q
                                                Q( f ) = Qi ( f ) * Q +
                                                                          2




©Yao Wang, 2006           EE3414:Quantization                                          8
Example

•   For the following sequence {1.2,-0.2,-0.5,0.4,0.89,1.3…}, Quantize it using a
    uniform quantizer in the range of (-1.5,1.5) with 4 levels, and write the quantized
    sequence.
•   Solution: Q=3/4=0.75. Quantizer is illustrated below.

                       -1.125            -0.375              0.375             1.125



                -1.5             -0.75                0                0.75              1.5


      Yellow dots indicate the partition levels (boundaries between separate quantization intervals)
      Red dots indicate the reconstruction levels (middle of each interval)

      1.2 fall between 0.75 and 1.5, and hence is quantized to 1.125

•   Quantized sequence:
      {1.125,-0.375,-0.375,0.375,1.125,1.125}



©Yao Wang, 2006                             EE3414:Quantization                                        9
Effect of Quantization Stepsize

                  Q=0.25                                           Q=0.5
     1.5                                    1.5

        1                                         1

     0.5                                    0.5

        0                                         0

    -0.5                                   -0.5

       -1                                     -1

    -1.5                                   -1.5
            0     0.2      0.4                        0          0.2              0.4
                                                          demo_sampling_quant.m




©Yao Wang, 2006             EE3414:Quantization                                         10
Demo: Audio Quantization

                      0.02


                                                            original at 16 bit
Original             0.015                                  quantized at 4 bit
Mozart.wav
                      0.01



                     0.005
Quantized
Mozart_q16.wav
                         0



                     -0.005



                      -0.01
                              2   2.002 2.004 2.006 2.008   2.01   2.012 2.014 2.016 2.018   2.02
                                                                                              4
                                                                                         x 10


   ©Yao Wang, 2006                    EE3414:Quantization                                           11
Demo: Audio Quantization (II)

 0.02                                                                            0.02
                                                                                                                                        original at 16 bit
                                                                                                                                        quantized at 6 bit
                                        original at 16 bit
0.015                                   quantized at 4 bit                      0.015



 0.01                                                                            0.01



0.005                                                                           0.005



    0                                                                               0



-0.005                                                                          -0.005



 -0.01                                                                           -0.01
         2    2.002 2.004 2.006 2.008   2.01   2.012 2.014 2.016 2.018   2.02            2   2.002 2.004 2.006 2.008   2.01   2.012 2.014 2.016 2.018        2.02
                                                                          4                                                                                   4
                                                                     x 10                                                                              x 10




                              Quantized                                                                        Quantized
                              Mozart_q16.wav                                                                   Mozart_q64.wav


             ©Yao Wang, 2006                                      EE3414:Quantization                                                                 12
Non-Uniform Quantization


• Problems with uniform quantization
      – Only optimal for uniformly distributed signal
      – Real audio signals (speech and music) are more
        concentrated near zeros
      – Human ear is more sensitive to quantization errors at small
        values
• Solution
      – Using non-uniform quantization
           • quantization interval is smaller near zero




©Yao Wang, 2006                 EE3414:Quantization                   13
Quantization: General Description




                  Quantization levels : L
                  Partition values : bl
                  Partition regions : Bl = [bl −1 , bl )
                  Reconstruction values : g l
                  Quantized Index : Qi ( f ) = l , if f ∈ Bl
                  Quantizer value : Q( f ) = g l , if f ∈ Bl

©Yao Wang, 2006               EE3414:Quantization              14
Function Representation




                    Q ( f ) = gl , if f ∈ Bl

©Yao Wang, 2006       EE3414:Quantization      15
Design of Non-Uniform Quantizer


• Directly design the partition and reconstruction levels
• Non-linear mapping+uniform quantization
              µ-law quantization




©Yao Wang, 2006                    EE3414:Quantization      16
µ-Law Quantization




                  y =F [ x ]
                                  |x| 
                          log 1+µ
                                  X max 
                                         .sign[ x]
                  = X max
                            log[1 + µ ]




©Yao Wang, 2006                     EE3414:Quantization   17
Implementation of µ-Law Quantization
           (Direct Method)

      – Transform the signal using µ-law: x->y
                       y =F [ x ]
                                       |x| 
                               log 1+µ
                                        X max 
                        = X max              .sign[ x]
                                 log[1 + µ ]


      – Quantize the transformed value using a uniform quantizer: y->y^
      – Transform the quantized value back using inverse µ-law: y^->x^

                         x =F −1[ y ]
                          X        log(1+ µ ) y 
                         = max    10 X max − 1 sign(y)
                           µ                    
                                                




©Yao Wang, 2006                     EE3414:Quantization                   18
Implementation of µ-Law Quantization
           (Indirect Method)

• Indirect Method:
      – Instead of applying the above computation to each sample,
        one can pre-design a quantization table (storing the partition
        and reconstruction levels) using the above procedure. The
        actual quantization process can then be done by a simple
        table look-up.
      – Applicable both for uniform and non-uniform quantizers
      – How to find the partition and reconstruction levels for mu-law
        quantizer
           • Apply inverse mu-law mapping to the partition and
             reconstruction levels of the uniform quantizer for y.
           • Note that the mu-law formula is designed so that if x ranges
             from (-x_max, x_max), then y also has the same range.


©Yao Wang, 2006                 EE3414:Quantization                         19
Example

•   For the following sequence {1.2,-0.2,-0.5,0.4,0.89,1.3…}, Quantize it
    using a mu-law quantizer in the range of (-1.5,1.5) with 4 levels, and
    write the quantized sequence.

•   Solution (indirect method):
      – apply the inverse formula to the partition and reconstruction levels found for
        the previous uniform quantizer example. Because the mu-law mapping is
        symmetric, we only need to find the inverse values for y=0.375,0.75,1.125
              µ=9, x_max=1.5, 0.375->0.1297, 0.75->0.3604, 1.125->0.7706
      – Then quantize each sample using the above partition and reconstruction
        levels.




©Yao Wang, 2006                     EE3414:Quantization                                  20
Example (cntd)

                   -1.125            -0.375                0.375             1.125



            -1.5             -0.75                 0                0.75               1.5

                                                                                 x =F −1[ y ]
                                                        Inverse µ-law
                                                                                      X       log(1+ µ ) y 
                                                                                     = max   10 X max − 1 sign(y)
                                                                                       µ                   
                                                                                                           
                            -0.77         -0.13     0.13              0.77


            -1.5                       -0.36        0      0.36                         1.5




 • Original sequence: {1.2,-0.2,-0.5,0.4,0.89,1.3…}
 • Quantized sequence
      – {0.77,-0.13,-0.77,0.77,0.77,0.77}
©Yao Wang, 2006                               EE3414:Quantization                                               21
Uniform vs. µ-Law Quantization

             Uniform: Q=0.5                               µ-law: Q=0.5,µ=16
1.5                                            1.5

   1                                              1
0.5                                            0.5

   0                                              0

-0.5                                          -0.5
  -1                                             -1

-1.5                                          -1.5
       0          0.2       0.4                       0       0.2        0.4

            With µ-law, small values are represented more accurately,
            but large values are represented more coarsely.


©Yao Wang, 2006                   EE3414:Quantization                          22
Uniform vs. µ-Law for Audio
            0.02                                  0.02
                                 q32                          q64

            0.01                                  0.01


                   0                                 0
  Mozart_q32.wav                                                              Mozart_q64.wav

           -0.01                                  -0.01
                       2       2.01      2.02             2    2.01      2.02
                                              4                               4
                                       x 10                            x 10
            0.02                                  0.02
                              q32µ4                           q32µ16
            0.01                                  0.01


                0
Mozart_q32_m4.wav                                    0
                                                                       Mozart_q32_m16.wav


           -0.01                                  -0.01
                       2       2.01      2.02             2    2.01      2.02
                                              4                               4
                                       x 10                            x 10
Evaluation of Quantizer Performance

 • Ideally we want to measure the performance by how close is the
   quantized sound to the original sound to our ears -- Perceptual
   Quality
 • But it is very hard to come up with a objective measure that
   correlates very well with the perceptual quality
 • Frequently used objective measure – mean square error (MSE)
   between original and quantized samples or signal to noise ratio
   (SNR)
                                1
                  MSE : σ q =
                          2

                                N
                                    ∑ ( x(n) − x(n))
                                    n
                                               ˆ       2



                                                 (
                  SNR(dB) : SNR = 10 log10 σ x / σ q
                                             2     2
                                                           )
                  where N is the number of samples in the sequence.
                                                                    1
                  σ x is the variance of the original signal, σ z2 = ∑ ( x(n)) 2
                    2

                                                                    N n

©Yao Wang, 2006                         EE3414:Quantization                        24
Sample Matlab Code

Go through “quant_uniform.m”, “quant_mulaw.m”




©Yao Wang, 2006        EE3414:Quantization      25
Binary Encoding


• Convert each quantized level index into a codeword
  consisting of binary bits
• Ex: natural binary encoding for 8 levels:
      – 000,001,010,011,100,101,110,111
• More sophisticated encoding (variable length coding)
      – Assign a short codeword to a more frequent symbol to
        reduce average bit rate
      – To be covered later




©Yao Wang, 2006             EE3414:Quantization                26
Example 1: uniform quantizer

•   For the following sequence {1.2,-0.2,-0.5,0.4,0.89,1.3…}, Quantize it using a
    uniform quantizer in the range of (-1.5,1.5) with 4 levels, and write the quantized
    sequence and the corresponding binary bitstream.
•   Solution: Q=3/4=0.75. Quantizer is illustrated below.
•   Codewords: 4 levels can be represented by 2 bits, 00, 01, 10, 11

      codewords                  00               01            10             11

     Quantized values          -1.125           -0.375          0.375          1.125



                        -1.5            -0.75             0             0.75           1.5



•   Quantized value sequence:
      {1.125,-0.375,-0.375,0.375,1.125,1.125}
•   Bitstream representing quantized sequence:
      {11, 01, 01, 10, 11, 11}



©Yao Wang, 2006                           EE3414:Quantization                                27
Example 2: mu-law quantizer
codewords               00                01                 10                 11
                       -1.125            -0.375                  0.375            1.125



                -1.5             -0.75                 0                 0.75               1.5

                                                                                      x =F −1[ y ]
                                                             Inverse µ-law
                                                                                           X       log(1+ µ ) y 
                                                                                          = max   10 X max − 1 sign(y)
  codewords                     00                01        10            11                µ                   
                                                                                                                
                                -0.77          -0.13    0.13               0.77


                -1.5                       -0.36        0        0.36                        1.5




     • Original sequence: {1.2,-0.2,-0.5,0.4,0.89,1.3…}
     • Quantized sequence: {0.77,-0.13,-0.77,0.77,0.77,0.77}
     • Bitstream: {11,01,00,11,11,11}
    ©Yao Wang, 2006                               EE3414:Quantization                                                28
Bit Rate of a Digital Sequence

• Sampling rate: f_s sample/sec
• Quantization resolution: B bit/sample, B=[log2(L)]
• Bit rate: R=f_s B bit/sec
• Ex: speech signal sampled at 8 KHz, quantized to 8 bit/sample,
  R=8*8 = 64 Kbps
• Ex: music signal sampled at 44 KHz, quantized to 16 bit/sample,
  R=44*16=704 Kbps
• Ex: stereo music with each channel at 704 Kbps: R=2*704=1.4
  Mbps
• Required bandwidth for transmitting a digital signal depends on
  the modulation technique.
      – To be covered later.
• Data rate of a multimedia signal can be reduced significantly
  through lossy compression w/o affecting the perceptual quality.
      – To be covered later.



©Yao Wang, 2006                EE3414:Quantization                  29
Advantages of Digital
                     Representation (I)
                       1.5
More immune to
noise added in                                               original signal
channel and/or                                               received signal
storage
                         1

The receiver applies
a threshold to the
received signal:       0.5

   0 if x < 0.5
 x=
 ˆ
   1 if x ≥ 0.5
                         0




                       -0.5
                              0   10         20         30        40           50   60




  ©Yao Wang, 2006                 EE3414:Quantization                                    30
Advantages of Digital
                   Representation (II)

• Can correct erroneous bits and/or recover missing
  bits using “forward error correction” (FEC) technique
      – By adding “parity bits” after information bits, corrupted bits
        can be detected and corrected
      – Ex: adding a “check-sum” to the end of a digital sequence
        (“0” if sum=even, “1” if sum=odd). By computing check-sum
        after receiving the signal, one can detect single errors (in
        fact, any odd number of bit errors).
      – Used in CDs, DVDs, Internet, wireless phones, etc.




©Yao Wang, 2006              EE3414:Quantization                         31
What Should You Know

• Understand the general concept of quantization
• Can perform uniform quantization on a given signal
• Understand the principle of non-uniform quantization, and can
  perform mu-law quantization
• Can perform uniform and mu-law quantization on a given
  sequence, generate the resulting quantized sequence and its
  binary representation
• Can calculate bit rate given sampling rate and quantization
  levels
• Know advantages of digital representation
• Understand sample matlab codes for performing quantization
  (uniform and mu-law)



©Yao Wang, 2006           EE3414:Quantization                     32
References

• Y. Wang, Lab Manual for Multimedia Lab, Experiment on
  Speech and Audio Compression. Sec. 1-2.1. (copies provided).




©Yao Wang, 2006          EE3414:Quantization                     33

More Related Content

PDF
quantization
PDF
Quantization
PDF
Sparsity and Compressed Sensing
PPT
Discrete Fourier Transform
PDF
WAVELET-PACKET-BASED ADAPTIVE ALGORITHM FOR SPARSE IMPULSE RESPONSE IDENTIFI...
PDF
A Classification Problem of Credit Risk Rating Investigated and Solved by Opt...
PPT
Decimation in time and frequency
PDF
An Introduction to Hidden Markov Model
quantization
Quantization
Sparsity and Compressed Sensing
Discrete Fourier Transform
WAVELET-PACKET-BASED ADAPTIVE ALGORITHM FOR SPARSE IMPULSE RESPONSE IDENTIFI...
A Classification Problem of Credit Risk Rating Investigated and Solved by Opt...
Decimation in time and frequency
An Introduction to Hidden Markov Model

What's hot (20)

PPT
Hmm viterbi
PDF
Fft presentation
PDF
fourier representation of signal and systems
PPT
Correlative level coding
PDF
Two dimensional Pool Boiling
PDF
Dsp U Lec07 Realization Of Discrete Time Systems
PPT
Isi and nyquist criterion
PDF
Elementary Landscape Decomposition of the Quadratic Assignment Problem
PDF
Dsp U Lec04 Discrete Time Signals & Systems
PDF
L. Perivolaropoulos, Topological Quintessence
PPT
Non newtonian models
PPT
Matched filter
PDF
Hidden Markov Models
PDF
Mapping Ash Tree Colonization in an Agricultural Moutain Landscape_ Investiga...
PPT
Cognitive radio
PDF
Dsp U Lec06 The Z Transform And Its Application
PPT
Alba ffs flim 2012
PPT
z transforms
PDF
Signal fundamentals
PDF
Solved problems
Hmm viterbi
Fft presentation
fourier representation of signal and systems
Correlative level coding
Two dimensional Pool Boiling
Dsp U Lec07 Realization Of Discrete Time Systems
Isi and nyquist criterion
Elementary Landscape Decomposition of the Quadratic Assignment Problem
Dsp U Lec04 Discrete Time Signals & Systems
L. Perivolaropoulos, Topological Quintessence
Non newtonian models
Matched filter
Hidden Markov Models
Mapping Ash Tree Colonization in an Agricultural Moutain Landscape_ Investiga...
Cognitive radio
Dsp U Lec06 The Z Transform And Its Application
Alba ffs flim 2012
z transforms
Signal fundamentals
Solved problems
Ad

Viewers also liked (20)

PDF
ATI Technical Training Short Course Underwater Acoustics for Biologists and C...
PDF
Fundamentals of Engineering Probability Visualization Techniques & MatLab Cas...
PDF
fundamentals_satellite_communication_part_1
PDF
ATI's Systems Engineering - Requirements technical training course sampler
PDF
Bioastronautics: Space Exploration and its Effects on the Human Body Course S...
PDF
whitepaper_mpeg-if_understanding_mpeg4
PDF
Fundamentals Of Space Systems & Space Subsystems course sampler
PDF
IntrRSCode
PDF
video_compression_2004
PDF
euler theorm
PDF
How Do Our Clients Use CONOPS?
PDF
ATI's Total Systems Engineering Development & Management technical training c...
PDF
ATI Systems Engineering - The People Dimension Professional Development Techn...
PDF
PPTX
Pakistani Chat Rooms,Chat-room,GupshupCorner-SatelliteLEC1,
PDF
ATI's Quantitative Methods course: Bridging Project Management and System Eng...
PDF
Teknologi Pita Lebar 4G LTE
PDF
Applied Physical Oceanography And Modeling
PDF
intro_dgital_TV
ATI Technical Training Short Course Underwater Acoustics for Biologists and C...
Fundamentals of Engineering Probability Visualization Techniques & MatLab Cas...
fundamentals_satellite_communication_part_1
ATI's Systems Engineering - Requirements technical training course sampler
Bioastronautics: Space Exploration and its Effects on the Human Body Course S...
whitepaper_mpeg-if_understanding_mpeg4
Fundamentals Of Space Systems & Space Subsystems course sampler
IntrRSCode
video_compression_2004
euler theorm
How Do Our Clients Use CONOPS?
ATI's Total Systems Engineering Development & Management technical training c...
ATI Systems Engineering - The People Dimension Professional Development Techn...
Pakistani Chat Rooms,Chat-room,GupshupCorner-SatelliteLEC1,
ATI's Quantitative Methods course: Bridging Project Management and System Eng...
Teknologi Pita Lebar 4G LTE
Applied Physical Oceanography And Modeling
intro_dgital_TV
Ad

Similar to quantization (20)

PDF
Quantifying the call blending balance in two way communication retrial queues...
PPT
Quadrature amplitude modulation qam transmitter
PDF
Cosmological Perturbations and Numerical Simulations
PPT
An automated and user-friendly optical tweezers for biomolecular investigat...
PPT
Finite automata examples
PPT
Finite automata examples
PDF
Ee443 phase locked loop - presentation - schwappach and brandy
PDF
EC8553 Discrete time signal processing
PPT
Fourier transform
PPT
Chapter 5
PDF
Aquifer Parameter Estimation
PDF
SOCG: Linear-Size Approximations to the Vietoris-Rips Filtration
PDF
Ultrasound Modular Architecture
PDF
Short-time homomorphic wavelet estimation
PDF
Signal Processing Course : Sparse Regularization of Inverse Problems
PPTX
Dissertation Slides
PDF
chapter5_marked_optimization_with_SGD.pdf
PDF
Tuto cvpr part1
PDF
CVPR2010: Sparse Coding and Dictionary Learning for Image Analysis: Part 1: S...
PDF
IGARSS2011 FR3.T08.3 BenDavid.pdf
Quantifying the call blending balance in two way communication retrial queues...
Quadrature amplitude modulation qam transmitter
Cosmological Perturbations and Numerical Simulations
An automated and user-friendly optical tweezers for biomolecular investigat...
Finite automata examples
Finite automata examples
Ee443 phase locked loop - presentation - schwappach and brandy
EC8553 Discrete time signal processing
Fourier transform
Chapter 5
Aquifer Parameter Estimation
SOCG: Linear-Size Approximations to the Vietoris-Rips Filtration
Ultrasound Modular Architecture
Short-time homomorphic wavelet estimation
Signal Processing Course : Sparse Regularization of Inverse Problems
Dissertation Slides
chapter5_marked_optimization_with_SGD.pdf
Tuto cvpr part1
CVPR2010: Sparse Coding and Dictionary Learning for Image Analysis: Part 1: S...
IGARSS2011 FR3.T08.3 BenDavid.pdf

More from aniruddh Tyagi (20)

PDF
BUC BLOCK UP CONVERTER
PDF
digital_set_top_box2
PDF
Discrete cosine transform
PDF
EBU_DVB_S2 READY TO LIFT OFF
PDF
ADVANCED DVB-C,DVB-S STB DEMOD
PDF
DVB_Arch
PDF
haffman coding DCT transform
PDF
Classification
PDF
tyagi 's doc
PDF
quantization_PCM
PDF
ECMG & EMMG protocol
PDF
7015567A
PDF
Basic of BISS
PDF
art_sklar7_reed-solomon
PDF
DVBSimulcrypt2
PDF
en_302769v010101v
PDF
Euler formula
PDF
video compression
PDF
fundamentals of linux
BUC BLOCK UP CONVERTER
digital_set_top_box2
Discrete cosine transform
EBU_DVB_S2 READY TO LIFT OFF
ADVANCED DVB-C,DVB-S STB DEMOD
DVB_Arch
haffman coding DCT transform
Classification
tyagi 's doc
quantization_PCM
ECMG & EMMG protocol
7015567A
Basic of BISS
art_sklar7_reed-solomon
DVBSimulcrypt2
en_302769v010101v
Euler formula
video compression
fundamentals of linux

Recently uploaded (20)

PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
Teaching material agriculture food technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Spectroscopy.pptx food analysis technology
PDF
cuic standard and advanced reporting.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Tartificialntelligence_presentation.pptx
Group 1 Presentation -Planning and Decision Making .pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Teaching material agriculture food technology
20250228 LYD VKU AI Blended-Learning.pptx
Machine Learning_overview_presentation.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Reach Out and Touch Someone: Haptics and Empathic Computing
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Weekly Chronicles - August'25-Week II
Spectroscopy.pptx food analysis technology
cuic standard and advanced reporting.pdf
Encapsulation theory and applications.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
Empathic Computing: Creating Shared Understanding
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
Tartificialntelligence_presentation.pptx

quantization

  • 1. Quantization Yao Wang Polytechnic University, Brooklyn, NY11201 http://eeweb.poly.edu/~yao
  • 2. Outline • Review the three process of A to D conversion • Quantization – Uniform – Non-uniform • Mu-law – Demo on quantization of audio signals – Sample Matlab codes • Binary encoding – Bit rate of digital signals • Advantage of digital representation ©Yao Wang, 2006 EE3414:Quantization 2
  • 3. Three Processes in A/D Conversion Sampling Quanti- Binary zation Encoding xc(t) x[n] = xc(nT) x[n] c[n] Sampling Quantization Binary Period Interval codebook T Q • Sampling: take samples at time nT – T: sampling period; – fs = 1/T: sampling frequency • Quantization: map amplitude values into a set of discrete values kQ – Q: quantization interval or stepsize • Binary Encoding – Convert each quantized value into a binary codeword ©Yao Wang, 2006 EE3414:Quantization 3
  • 4. Analog to Digital Conversion 1 T=0.1 Q=0.25 0.5 0 -0.5 A2D_plot.m -1 0 0.2 0.4 0.6 0.8 1 ©Yao Wang, 2006 EE3414:Quantization 4
  • 5. How to determine T and Q? • T (or fs) depends on the signal frequency range – A fast varying signal should be sampled more frequently! – Theoretically governed by the Nyquist sampling theorem • fs > 2 fm (fm is the maximum signal frequency) • For speech: fs >= 8 KHz; For music: fs >= 44 KHz; • Q depends on the dynamic range of the signal amplitude and perceptual sensitivity – Q and the signal range D determine bits/sample R • 2R=D/Q • For speech: R = 8 bits; For music: R =16 bits; • One can trade off T (or fs) and Q (or R) – lower R -> higher fs; higher R -> lower fs • We considered sampling in last lecture, we discuss quantization in this lecture ©Yao Wang, 2006 EE3414:Quantization 5
  • 6. Uniform Quantization • Applicable when the signal is in a finite range (fmin, fmax) • The entire data range is divided into L equal intervals of length Q (known as quantization interval or quantization step-size) Q=(fmax-fmin)/L • Interval i is mapped to the middle value of this interval • We store/send only the index of f − f min  quantized value Index of quantized value = Qi ( f ) =    Q  Quantized value = Q ( f ) = Qi ( f )Q + Q / 2 + f min ©Yao Wang, 2006 EE3414:Quantization 6
  • 7. Special Case I: Signal range is symmetric • (a) L=even, mid-rise Q(f)=floor(f/q)*q+q/2 L = even, Mid - Riser L = odd, Mid - Tread f Q f Qi ( f ) = floor ( ), Q ( f ) = Qi ( f ) * Q + Qi ( f ) = round ( ), Q( f ) = Qi ( f ) * Q Q 2 Q ©Yao Wang, 2006 EE3414:Quantization 7
  • 8. Special Case II: Signal range starts at 0 f min = 0, B = f max , q = f max / L f Qi ( f ) = floor ( ) Q Q Q( f ) = Qi ( f ) * Q + 2 ©Yao Wang, 2006 EE3414:Quantization 8
  • 9. Example • For the following sequence {1.2,-0.2,-0.5,0.4,0.89,1.3…}, Quantize it using a uniform quantizer in the range of (-1.5,1.5) with 4 levels, and write the quantized sequence. • Solution: Q=3/4=0.75. Quantizer is illustrated below. -1.125 -0.375 0.375 1.125 -1.5 -0.75 0 0.75 1.5 Yellow dots indicate the partition levels (boundaries between separate quantization intervals) Red dots indicate the reconstruction levels (middle of each interval) 1.2 fall between 0.75 and 1.5, and hence is quantized to 1.125 • Quantized sequence: {1.125,-0.375,-0.375,0.375,1.125,1.125} ©Yao Wang, 2006 EE3414:Quantization 9
  • 10. Effect of Quantization Stepsize Q=0.25 Q=0.5 1.5 1.5 1 1 0.5 0.5 0 0 -0.5 -0.5 -1 -1 -1.5 -1.5 0 0.2 0.4 0 0.2 0.4 demo_sampling_quant.m ©Yao Wang, 2006 EE3414:Quantization 10
  • 11. Demo: Audio Quantization 0.02 original at 16 bit Original 0.015 quantized at 4 bit Mozart.wav 0.01 0.005 Quantized Mozart_q16.wav 0 -0.005 -0.01 2 2.002 2.004 2.006 2.008 2.01 2.012 2.014 2.016 2.018 2.02 4 x 10 ©Yao Wang, 2006 EE3414:Quantization 11
  • 12. Demo: Audio Quantization (II) 0.02 0.02 original at 16 bit quantized at 6 bit original at 16 bit 0.015 quantized at 4 bit 0.015 0.01 0.01 0.005 0.005 0 0 -0.005 -0.005 -0.01 -0.01 2 2.002 2.004 2.006 2.008 2.01 2.012 2.014 2.016 2.018 2.02 2 2.002 2.004 2.006 2.008 2.01 2.012 2.014 2.016 2.018 2.02 4 4 x 10 x 10 Quantized Quantized Mozart_q16.wav Mozart_q64.wav ©Yao Wang, 2006 EE3414:Quantization 12
  • 13. Non-Uniform Quantization • Problems with uniform quantization – Only optimal for uniformly distributed signal – Real audio signals (speech and music) are more concentrated near zeros – Human ear is more sensitive to quantization errors at small values • Solution – Using non-uniform quantization • quantization interval is smaller near zero ©Yao Wang, 2006 EE3414:Quantization 13
  • 14. Quantization: General Description Quantization levels : L Partition values : bl Partition regions : Bl = [bl −1 , bl ) Reconstruction values : g l Quantized Index : Qi ( f ) = l , if f ∈ Bl Quantizer value : Q( f ) = g l , if f ∈ Bl ©Yao Wang, 2006 EE3414:Quantization 14
  • 15. Function Representation Q ( f ) = gl , if f ∈ Bl ©Yao Wang, 2006 EE3414:Quantization 15
  • 16. Design of Non-Uniform Quantizer • Directly design the partition and reconstruction levels • Non-linear mapping+uniform quantization µ-law quantization ©Yao Wang, 2006 EE3414:Quantization 16
  • 17. µ-Law Quantization y =F [ x ]  |x|  log 1+µ  X max  .sign[ x] = X max log[1 + µ ] ©Yao Wang, 2006 EE3414:Quantization 17
  • 18. Implementation of µ-Law Quantization (Direct Method) – Transform the signal using µ-law: x->y y =F [ x ]  |x|  log 1+µ X max  = X max  .sign[ x] log[1 + µ ] – Quantize the transformed value using a uniform quantizer: y->y^ – Transform the quantized value back using inverse µ-law: y^->x^ x =F −1[ y ] X  log(1+ µ ) y  = max 10 X max − 1 sign(y) µ     ©Yao Wang, 2006 EE3414:Quantization 18
  • 19. Implementation of µ-Law Quantization (Indirect Method) • Indirect Method: – Instead of applying the above computation to each sample, one can pre-design a quantization table (storing the partition and reconstruction levels) using the above procedure. The actual quantization process can then be done by a simple table look-up. – Applicable both for uniform and non-uniform quantizers – How to find the partition and reconstruction levels for mu-law quantizer • Apply inverse mu-law mapping to the partition and reconstruction levels of the uniform quantizer for y. • Note that the mu-law formula is designed so that if x ranges from (-x_max, x_max), then y also has the same range. ©Yao Wang, 2006 EE3414:Quantization 19
  • 20. Example • For the following sequence {1.2,-0.2,-0.5,0.4,0.89,1.3…}, Quantize it using a mu-law quantizer in the range of (-1.5,1.5) with 4 levels, and write the quantized sequence. • Solution (indirect method): – apply the inverse formula to the partition and reconstruction levels found for the previous uniform quantizer example. Because the mu-law mapping is symmetric, we only need to find the inverse values for y=0.375,0.75,1.125 µ=9, x_max=1.5, 0.375->0.1297, 0.75->0.3604, 1.125->0.7706 – Then quantize each sample using the above partition and reconstruction levels. ©Yao Wang, 2006 EE3414:Quantization 20
  • 21. Example (cntd) -1.125 -0.375 0.375 1.125 -1.5 -0.75 0 0.75 1.5 x =F −1[ y ] Inverse µ-law X  log(1+ µ ) y  = max 10 X max − 1 sign(y) µ     -0.77 -0.13 0.13 0.77 -1.5 -0.36 0 0.36 1.5 • Original sequence: {1.2,-0.2,-0.5,0.4,0.89,1.3…} • Quantized sequence – {0.77,-0.13,-0.77,0.77,0.77,0.77} ©Yao Wang, 2006 EE3414:Quantization 21
  • 22. Uniform vs. µ-Law Quantization Uniform: Q=0.5 µ-law: Q=0.5,µ=16 1.5 1.5 1 1 0.5 0.5 0 0 -0.5 -0.5 -1 -1 -1.5 -1.5 0 0.2 0.4 0 0.2 0.4 With µ-law, small values are represented more accurately, but large values are represented more coarsely. ©Yao Wang, 2006 EE3414:Quantization 22
  • 23. Uniform vs. µ-Law for Audio 0.02 0.02 q32 q64 0.01 0.01 0 0 Mozart_q32.wav Mozart_q64.wav -0.01 -0.01 2 2.01 2.02 2 2.01 2.02 4 4 x 10 x 10 0.02 0.02 q32µ4 q32µ16 0.01 0.01 0 Mozart_q32_m4.wav 0 Mozart_q32_m16.wav -0.01 -0.01 2 2.01 2.02 2 2.01 2.02 4 4 x 10 x 10
  • 24. Evaluation of Quantizer Performance • Ideally we want to measure the performance by how close is the quantized sound to the original sound to our ears -- Perceptual Quality • But it is very hard to come up with a objective measure that correlates very well with the perceptual quality • Frequently used objective measure – mean square error (MSE) between original and quantized samples or signal to noise ratio (SNR) 1 MSE : σ q = 2 N ∑ ( x(n) − x(n)) n ˆ 2 ( SNR(dB) : SNR = 10 log10 σ x / σ q 2 2 ) where N is the number of samples in the sequence. 1 σ x is the variance of the original signal, σ z2 = ∑ ( x(n)) 2 2 N n ©Yao Wang, 2006 EE3414:Quantization 24
  • 25. Sample Matlab Code Go through “quant_uniform.m”, “quant_mulaw.m” ©Yao Wang, 2006 EE3414:Quantization 25
  • 26. Binary Encoding • Convert each quantized level index into a codeword consisting of binary bits • Ex: natural binary encoding for 8 levels: – 000,001,010,011,100,101,110,111 • More sophisticated encoding (variable length coding) – Assign a short codeword to a more frequent symbol to reduce average bit rate – To be covered later ©Yao Wang, 2006 EE3414:Quantization 26
  • 27. Example 1: uniform quantizer • For the following sequence {1.2,-0.2,-0.5,0.4,0.89,1.3…}, Quantize it using a uniform quantizer in the range of (-1.5,1.5) with 4 levels, and write the quantized sequence and the corresponding binary bitstream. • Solution: Q=3/4=0.75. Quantizer is illustrated below. • Codewords: 4 levels can be represented by 2 bits, 00, 01, 10, 11 codewords 00 01 10 11 Quantized values -1.125 -0.375 0.375 1.125 -1.5 -0.75 0 0.75 1.5 • Quantized value sequence: {1.125,-0.375,-0.375,0.375,1.125,1.125} • Bitstream representing quantized sequence: {11, 01, 01, 10, 11, 11} ©Yao Wang, 2006 EE3414:Quantization 27
  • 28. Example 2: mu-law quantizer codewords 00 01 10 11 -1.125 -0.375 0.375 1.125 -1.5 -0.75 0 0.75 1.5 x =F −1[ y ] Inverse µ-law X  log(1+ µ ) y  = max 10 X max − 1 sign(y) codewords 00 01 10 11 µ     -0.77 -0.13 0.13 0.77 -1.5 -0.36 0 0.36 1.5 • Original sequence: {1.2,-0.2,-0.5,0.4,0.89,1.3…} • Quantized sequence: {0.77,-0.13,-0.77,0.77,0.77,0.77} • Bitstream: {11,01,00,11,11,11} ©Yao Wang, 2006 EE3414:Quantization 28
  • 29. Bit Rate of a Digital Sequence • Sampling rate: f_s sample/sec • Quantization resolution: B bit/sample, B=[log2(L)] • Bit rate: R=f_s B bit/sec • Ex: speech signal sampled at 8 KHz, quantized to 8 bit/sample, R=8*8 = 64 Kbps • Ex: music signal sampled at 44 KHz, quantized to 16 bit/sample, R=44*16=704 Kbps • Ex: stereo music with each channel at 704 Kbps: R=2*704=1.4 Mbps • Required bandwidth for transmitting a digital signal depends on the modulation technique. – To be covered later. • Data rate of a multimedia signal can be reduced significantly through lossy compression w/o affecting the perceptual quality. – To be covered later. ©Yao Wang, 2006 EE3414:Quantization 29
  • 30. Advantages of Digital Representation (I) 1.5 More immune to noise added in original signal channel and/or received signal storage 1 The receiver applies a threshold to the received signal: 0.5 0 if x < 0.5 x= ˆ 1 if x ≥ 0.5 0 -0.5 0 10 20 30 40 50 60 ©Yao Wang, 2006 EE3414:Quantization 30
  • 31. Advantages of Digital Representation (II) • Can correct erroneous bits and/or recover missing bits using “forward error correction” (FEC) technique – By adding “parity bits” after information bits, corrupted bits can be detected and corrected – Ex: adding a “check-sum” to the end of a digital sequence (“0” if sum=even, “1” if sum=odd). By computing check-sum after receiving the signal, one can detect single errors (in fact, any odd number of bit errors). – Used in CDs, DVDs, Internet, wireless phones, etc. ©Yao Wang, 2006 EE3414:Quantization 31
  • 32. What Should You Know • Understand the general concept of quantization • Can perform uniform quantization on a given signal • Understand the principle of non-uniform quantization, and can perform mu-law quantization • Can perform uniform and mu-law quantization on a given sequence, generate the resulting quantized sequence and its binary representation • Can calculate bit rate given sampling rate and quantization levels • Know advantages of digital representation • Understand sample matlab codes for performing quantization (uniform and mu-law) ©Yao Wang, 2006 EE3414:Quantization 32
  • 33. References • Y. Wang, Lab Manual for Multimedia Lab, Experiment on Speech and Audio Compression. Sec. 1-2.1. (copies provided). ©Yao Wang, 2006 EE3414:Quantization 33